//
//  StatusForwardCell.swift
//  TWeibo
//
//  Created by wtw on 15/8/6.
//  Copyright © 2015年 wtw. All rights reserved.
//

import UIKit

class StatusForwardCell: StatusCell {

    //重写属性，不会覆盖父类的方法
    override var status: Status? {
        didSet {
            let userName = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            
            forwardLabel.text = userName + ": "  + text
        }
    }

    //设置UI界面
    override func setupUI() {
        super.setupUI()
        
        //1.添加控件 
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(forwardLabel, aboveSubview: backButton)
        
        //2.自动布局
        //背景的布局
        backButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -statusCellContentMargin, y: statusCellContentMargin))
        backButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        //转发文本的布局
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backButton, size: nil, offset: CGPoint(x: statusCellContentMargin, y: statusCellContentMargin))
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Width, multiplier: 1.0, constant: -2 * statusCellContentMargin))
        // 3 配图视图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: statusCellContentMargin))
        pictureWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureTopCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)
    }
  
    //MARK: -懒加载控件
    ///背景按钮
    private lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.93, alpha: 1.0)
        return btn
    }()
    
    /// 转发文字
    private lazy var forwardLabel: UILabel = {
    
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        label.numberOfLines = 0
        return label
    }()
}